<template>
  <div class="main">
    <div class="container">
      <div class="title">
        <div class="line"></div>
        <div class="text">模型类型</div>
      </div>
      <div class="content">
        <div class="type">
          <div :class="chooseName === '单选' ? 'selected' : 'normal'" @click="choose('单选')">单 选</div>
          <div :class="chooseName === '多选' ? 'selected' : 'normal'" @click="choose('多选')">多 选</div>
          <div :class="chooseName === '数字选择器' ? 'selected' : 'normal'" @click="choose('数字选择器')">数字选择器</div>
        </div>
        <div class="space" />
        <div class="options" v-for="(item, index) in singleOptions">
          <div class="sub-title" v-text="chooseName + `选项-` + (index + 1)"></div>
          <div class="input">
            <van-field v-model="item.name" type="digit" class="name" v-if="chooseName === '数字选择器'" placeholder="请输入整数"/>
            <van-field :border="false" v-model="item.name" placeholder="请输入选项内容" class="name" v-if="chooseName !== '数字选择器'"/>
            <!-- 允许输入正整数，调起纯数字键盘 -->
            <img :src="icons.addIcon" class="add" @click="addOption" v-if="chooseName !== '数字选择器'">
          </div>

          <van-divider />
        </div>
      </div>
    </div>
  </div>
  <div class="tab-bottom">
    <div class="confirm" @click="confirm">确 认</div>
    <div class="reset" @click="reset">重 置</div>
  </div>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import addIcon from '@/assets/imgs/workbench/wb_edit_add.png';
import router from '@/router';

const emit = defineEmits(['callback'])
const icons = reactive({
  addIcon: addIcon
})
const chooseName = ref('单选')
const singleOptions = ref([{
  name: '',
  checked: false
}])

const addOption = () => {
  singleOptions.value.push({
    name: '',
    checked: false
  })
}

const choose = (id: any) => {
  chooseName.value = id
}
//确认
const confirm = () => {
  const options = new Array()
  for (let i = 0; i < singleOptions.value.length; i++) {
    if (singleOptions.value[i].name) options.push(singleOptions.value[i])
  }
  const item = {
    optionContentType: chooseName.value,
    optionAnswer: options
  }
  emit('callback', JSON.stringify(item))
  router.back()
}
//重置
const reset = () => {
  singleOptions.value = [{
    name: '',
    checked: false
  }]
  console.log('重置')
}

</script>
<style lang="scss" scoped>
.main {
  background-color: #F1F6F9;
  position: absolute;
  left: 0;
  top: 44px;
  right: 0;
  bottom: 0;

  .container {
    display: flex;
    flex-direction: column;
    padding: 0 12px 62px 12px;
    box-sizing: border-box;

    .title {
      display: flex;
      align-items: center;
      margin-top: 16px;

      .line {
        width: 4px;
        height: 16px;
        margin-right: 8px;
        background-color: $primary-color;
      }

      .text {
        font-weight: 700;
        text-align: left;
        color: #181818;
        line-height: 12px;
        font-size: 18px;
      }
    }

    .content {
      width: 100%;
      display: flex;
      flex-direction: column;
      padding: 12px 16px;
      margin-top: 16px;
      background: #ffffff;
      border-radius: 5px;
      box-shadow: 0.5px 0.87px 4.5px 1px rgba(0, 0, 0, 0.05);
      box-sizing: border-box;

      .type {
        display: flex;
        border-radius: 2px;
        border: 1px solid #ececec;
        box-sizing: border-box;

        .normal {
          flex: 1;
          height: 30px;
          background: #ffffff;
          text-align: center;
          line-height: 30px;
        }

        .selected {
          flex: 1;
          height: 30px;
          background: #f1f4ff;
          text-align: center;
          line-height: 30px;
          color: #4c69dc;
        }
      }

      .space {
        height: 22px;
      }

      .options {

        .sub-title {
          font-size: 14px;
          font-weight: bold;
          text-align: left;
          color: #1f2e4c;
        }

        .input {
          display: flex;
          box-sizing: border-box;
          align-items: center;
          margin-top: 8px;

          .name {
            flex: 1;
            background-color: #FFFFFF;
            border: 0.5px solid #F7F7F7;
            border-radius: 5px;
            font-size: 10px;
            padding: 0 0 0 14px;
            background: url('../../../../assets/imgs/workbench/wb_bi_input.png');
          }

          .add {
            width: 12px;
            height: 12px;
            margin-left: 12px;
          }
        }

      }

    }
  }


  .tab-bottom {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 50px;
    background: #ffffff;
    box-shadow: 0px -1px 2.5px 1px rgba(0, 0, 0, 0.03), -0.5px 0px 0px 0.5px #ebebeb inset;
    line-height: 100px;
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 0 6px;
    box-sizing: border-box;

    .confirm {
      height: 30px;
      background: #f1f4ff;
      border-radius: 5px;
      flex: 1;
      text-align: center;
      margin: 0 6px;
      line-height: 30px;
      font-size: 14px;
      font-family: PingFang SC, PingFang SC-Medium;
      font-weight: bold;
      color: #4c69dc;
    }

    .reset {
      height: 30px;
      background: #f7f7f7;
      border-radius: 5px;
      flex: 1;
      text-align: center;
      margin: 0 6px;
      line-height: 30px;
      font-size: 14px;
      font-family: PingFang SC, PingFang SC-Medium;
      font-weight: bold;
      color: #4c69dc;
    }
  }
}
</style>